package vip.zslaa.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import vip.zslaa.entity.Blog;

import java.util.List;
import java.util.Map;

/**
 * @author ：zslaa
 * @date ：Created in 9/8/2019 7:14 PM
 * @description：
 * @version: $
 */
@Controller
public class BlogController {
    @Autowired
    private MongoTemplate mongoTemplate;

    //添加博客
    @RequestMapping("/insert")
    @ResponseBody
    public String insert(Blog blog){
        this.mongoTemplate.insert(blog);
        return "OK";
    }
    @RequestMapping("/index")
    public String index(Map map){
        return "index";
    }

    @GetMapping("/preview")
    public String preview( Map map) {
        Query query = new Query(Criteria.where("_id").is("5d75026964fb552248dc3215"));
        Blog blog = this.mongoTemplate.findOne(query,Blog.class);
        System.out.println(blog.toString());
        map.put("blog", blog);
        return "preview";
    }
}
